﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlServerCe;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;

public partial class MasterPage : System.Web.UI.MasterPage
{
    private System.ComponentModel.BackgroundWorker backgroundWorker1;
    PomocC c1 = new PomocC("asa");
    LogowanieInterface log;
    Login login;
    ForumDataContext fd;
    static string userName = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        log = new LogowanieInterface(LogowaniePanel);
        
        log.Draw();
        //log.DrawLogout("jan Admin");

        if (log.btnLogin != null) log.btnLogin.Command += new CommandEventHandler(Btn_Login);
        if (log.btnLogout != null) log.btnLogout.Command += new CommandEventHandler(Btn_Logout);
  
    }


    private void InitializeComponent()
    {
        
    }

    void Btn_Login(object sender, CommandEventArgs e) // co ma sie dziać po kliknięciu loguj
    {
        
        fd = new ForumDataContext();
        login = new Login(fd);
        if( (log.GetSetUserID = login.tryLogin(log.GetSetUsernameText,log.GetSetPasswordText))>=0)
        {
            userName = log.GetSetUsernameText;
            log.GetSetUserName = log.GetSetUsernameText; 
            log.GetSetUserInterface = "logout";
            Response.Redirect(Request.Url.ToString());
        }

    }
    void Btn_Logout(object sender, CommandEventArgs e) //co się dzieje po kliknięciu wyloguj
    {
        userName = null;
        log.GetSetUserName = null; 
        log.GetSetUserInterface = "login";
        log.GetSetUserID = -1;
        Response.Redirect(Request.Url.ToString());
    }

   

   
}
